/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package atm;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Albert
 */
public class BankAccount
{

    public static BankAccount getFromDB(String sUserCard, String sAccType)
    {
        BankAccount ba = null;

        String query = "select * from account_details right outer join bank_accounts " +
                       "on bank_accounts.Account_Number = account_details.Account_Number " +
                       "where card_number = " + sUserCard + " and account_type_ID = " + sAccType;

        ResultSet rs = Utils.GetQuerySet(query);
        if (rs == null)
        {
            return null;
        }
        else
        try
        {
            if (rs.first())
            {
               ba = new BankAccount();
               ba.type = rs.getString("Account_Type_ID");
               ba.balance = rs.getFloat("Balance");
               ba.account_number = rs.getString("Account_Number");
               ba.availWithdraw = rs.getFloat("Allowable_Withdrawal");
               ba.availBalance = rs.getFloat("Available_Balance");
            }
        }
        catch (SQLException ex)
        {
            Logger.getLogger(PINPage.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }



        return ba;
    }

    private String account_number;
    public void setAccountNumber(String s)
    {
      account_number = s;
    }
    public void setAccountNumber(int i)
    {
      account_number = Integer.toString(i);
    }
    public String getAccountNumber()
    {
      return account_number;
    }

    private String type;
    private float balance;


    private float availBalance;
    private float availWithdraw;

    /**
     * @return the balance
     */
    public float getBalance() {
        return balance;
    }

    /**
     * @param balance the balance to set
     */
    public void setBalance(float balance) 
    {

        this.balance = balance;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the availBalance
     */
    public float getAvailBalance() {
        return availBalance;
    }

    /**
     * @param availBalance the availBalance to set
     */
    public void setAvailBalance(float availBalance) {
        this.availBalance = availBalance;
    }

    /**
     * @return the availWithdraw
     */
    public float getAvailWithdraw() {
        return availWithdraw;
    }

    /**
     * @param availWithdraw the availWithdraw to set
     */
    public void setAvailWithdraw(float availWithdraw) {
        this.availWithdraw = availWithdraw;
    }

}
